write, a, program in a Java to print your school name four times in separate line
Answers
Answered by
112
class brainly
{
public static void main()
{
System.out.println("Delhi Public School");
System.out.println("Delhi Public School");
System.out.println("Delhi Public School");
System.out.println("Delhi Public School");
}
}
{
public static void main()
{
System.out.println("Delhi Public School");
System.out.println("Delhi Public School");
System.out.println("Delhi Public School");
System.out.println("Delhi Public School");
}
}
9Samridhirankawat1:
thnk but It didn't help to me
Answered by
15
Below are the java code for the above question:
Explanation:
import java.util.Scanner; // header file inclusion.
public class Print_name //class definition.
{
public static void main(String[] args) { // main function definition.
Scanner input_for = new Scanner(System.in); // object to take input.
String School_name = input_for.nextLine(); // input function to take input.
for(int i=0;i<4;i++)// for loop which executes four times
System.out.println(School_name); //print the school name in different line.
}
}
Output:
- If the user input "abc" as a school name then it will prints abc in four times in different line.
Code Explanation:
- The first line of the main function creates an object of Scanner class which takes the input for the school name.
- Then the loop will execute 4 times and print the school name for every iteration of the loop in different lines.
- The line change can be done with the help of print() function.
Learn More:
- Java program : https://brainly.in/question/7382524
Similar questions