2017-01-14 29 views
-1

Я пытаюсь выполнить простые вычисления скорости. Но мои коды не будут компилироваться. Я не уверен, что с ним не так. Любая помощь будет мне полезной, поскольку я новичок в Java.Проблемы с компиляцией Java

public class VelocityFall 
    { 
public static void main (String [] a) 
    { 
    Scanner s = new Scanner (System.in); 
    System.out.print("This program prints a table that shows each \nsecond," 
    + 
    "height from the ground (meters), and the velocity (m/s)\n of a free- 
    falling" + 
    "object from an initial height (metres).\nPlease input the Initial 
    Height H: "); 


    // input/get the value of H from the keyboard 
    int H = s.nextInt(); 
    // we need to design/output the table by using println with lines and 
    tabs (\t) 

    System.out.println ("------------------------------------------"); 
    System.out.println (" Second\t\tHeight\t\tVelocity"); 
    System.out.println ("------------------------------------------"); 

    //we now require a for loop 
    for (int t = 0; t<=15; t++) 
    { 
    // we are now going to calculate and output the velocity 
    double velocity = Math.sqrt(2*9.8*H); 
    System.out.println (t++"\t\t"+H"\t\t"+velocity); 

    } 
    } 
    } 

enter image description here

+3

Какое сообщение об ошибке? – luk2302

+1

'tabs (\ t)' выглядит очень подозрительно. – Marvin

+1

И, 'System.out.println (t +" \ t \ t "+ H +" \ t \ t "+ velocity);' –

ответ

1

У вас есть проблемы в вашем:

System.out.println (t++"\t\t"+H"\t\t"+velocity); 
//--------------------^--------^ 

Вам нужно что-то вроде этого:

System.out.println(t + "\t\t" + H + "\t\t" + velocity); 
//-----------------^-^------------^ 

Я думаю, что вы хотите сделать некоторые вкладки, как это:

Второй **** Tab **** H **** Tab **** Скорость

Вы можете узнать больше здесь: How to insert multiple tabs string in java?

Вы можете получить этот результат в конце :

This program prints a table that shows each 
second,height from the ground (meters), and the velocity (m/s) 
of a free-fallingobject from an initial height (metres). 
Please input the Initial Height H: 3 
------------------------------------------ 
Second  Height  Velocity 
------------------------------------------ 
0  3  7.6681158050723255 
1  3  7.6681158050723255 
2  3  7.6681158050723255 
3  3  7.6681158050723255 
4  3  7.6681158050723255 
5  3  7.6681158050723255 
6  3  7.6681158050723255 
7  3  7.6681158050723255 
8  3  7.6681158050723255 
9  3  7.6681158050723255 
10  3  7.6681158050723255 
11  3  7.6681158050723255 
12  3  7.6681158050723255 
13  3  7.6681158050723255 
14  3  7.6681158050723255 
15  3  7.6681158050723255 
+0

Пожалуйста, можете ли вы сослаться на очень хорошую книгу/материал java? – lee

+0

@lee Я считаю, что лучший способ - все больше практиковать и начинать с проекта, поэтому вы можете получить от него много вещей, для книг, я думаю, что это не очень хорошая идея, чтобы изучить его с самого начала, потому что там есть много примеров в google и youtube, поэтому просто запустите простой проект, и когда вы найдете некоторые проблемы, которые вы можете найти в google, потому что лучший способ узнать это ** практика ** не просто теория, надеюсь, вы получите мою мысль, вы может найти много вещей здесь http://stackoverflow.com/documentation/java/topics –

+0

спасибо большое. cheers – lee