What will be printed out on each line?Scanner input = new Scanner("This\nhas 5\n4\nlines\n");System.out.println("%" + input.next() + "%"); System.out.println("%" + input.nextLine() + "%"); System.out.println("%" + input.nextLine() + "%"); System.out.println("%" + input.nextInt() + "%"); System.out.println("%" + input.nextLine() + "%"); System.out.println("%" + input.nextLine() + "%");
Question
What will be printed out on each line?Scanner input = new Scanner("This\nhas 5\n4\nlines\n");System.out.println("%" + input.next() + "%"); System.out.println("%" + input.nextLine() + "%"); System.out.println("%" + input.nextLine() + "%"); System.out.println("%" + input.nextInt() + "%"); System.out.println("%" + input.nextLine() + "%"); System.out.println("%" + input.nextLine() + "%");
Solution
The output will be:
%This% % has 5% %4% %lines% %%
Similar Questions
What will be printed out on each line?String note = "Minsub\n22\nCS";Scanner input = new Scanner(note);System.out.println("#" + input.nextLine() + "#"); System.out.println(input.nextInt()); System.out.println("#" + input.nextLine() + "#");
What will the following code print out when it is run?Scanner scnr = new Scanner("Hello \n\n World!");String c = scnr.next();String b = scnr.nextLine();String a = scnr.next();System.out.println(":" + a + ":" + b + ":");Group of answer choices:Hello:World!::World!: ::Hello: :: : World!:
String note = "14 23.0 \n\nhello\n cs200";Scanner input = new Scanner(note);System.out.println("$" + input.next() + "$"); System.out.println("$" + input.nextLine() + "$"); System.out.println("$" + input.nextLine() + "$");
Which of the following would output this to the screen?1. Some Output.2. Additional Output.int lineNumber = 1;String lineOne = "\n" + lineNumber + ". Some Output.";lineNumber++;String lineTwo = lineNumber++ + ". Additional Output.";System.out.println(lineOne + lineTwo);int lineNumber = 1;String lineOne = lineNumber + ". Some Output.\n";lineNumber++;String lineTwo = lineNumber + ". Additional Output.";System.out.println(lineOne + lineTwo);int lineNumber = 1;String lineOne = lineNumber + ". Some Output.";lineNumber++;String lineTwo = lineNumber + ". Additional Output.\n";System.out.println(lineOne + lineTwo);int lineNumber = 1;String lineOne = lineNumber + ". Some Output.";lineNumber++;String lineTwo = lineNumber + ". Additional Output.";System.out.println(lineOne + lineTwo);
import java.io.*;import java.util.*;public class Solution { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int Myint = scanner.nextInt(); double d = scanner.nextDouble(); scanner.nextLine(); String mystring = scanner.nextLine(); System.out.println(mystring); System.out.println(d); System.out.println(Myint); /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ }}
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.