import java.util.*;
import javax.swing.*;
public class ZhangIDK
{
public static void main (String[] args)
{
average (1, 2, 3, 4, 5, 6, 7);
least (1, 2, 3, 4, 5);
Scanner sc = new Scanner (System.in);
System.out.println ("Please enter a number");
int h = sc.nextInt();
System.out.println ("Please enter another number");
int i = sc.nextInt();
power (h, i);
System.out.println ("Please enter a number");
int k = sc.nextInt();
System.out.println ("Please enter a word");
String j = sc. nextLine();
repeater (j, k);
}
public static void average (int a, int b, int c, int d, int e, int f, int g)
{
int y = a + b + c + d + e + f + g;
y/=7;
System.out.println ("The average is" +y);
}
public static void least (int q, int r, int s, int t, int u)
{
int Smallestnumber = 100;
int number = 1;
if (number < Smallestnumber)
{
Smallestnumber = number;
number++;
}
System.out.println("The smallest number is" +Smallestnumber+ ".");
}
public static void power (int h, int i)
{
int result = 1;
for (int temp = 0; temp < i; temp++)
{
result *= h;
}
System.out.println (h);
}
public static void repeater (String j, int k)
{
for (int tem = 0; tem < k; tem++)
{
System.out.println (j + " ");
}
}
}
I'm a beginner at programming and my teacher assigned us these method practice problems.
In the first method, we were suppose to find the average of 7 pre declared numbers.
In the second method, we were suppose to find the smallest of 5 pre declared numbers.
In the third method, we were suppose to allow user to input two numbers which the program will raise the first number to the power of the second. For example: the user inputs 2, and 4, the program will SOP 2^4, which is 16.
In the fourth method, we were suppose to allow the use to input a word and a number and the program should SOP the word as many times as the number. For example: the user inputs BOB and 2, the program should SOP BOB BOB
My problem is with the last method, the question will pop up asking "Please enter a word" but the program wont allow me to type a word and therefore I have no way of checking if my code works. How do I get the code to let me enter in a word?